package main;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Machine {
	/**
	 * Parses input
	 */
	public Parser parser;
	/**
	 * File to write ending state to.
	 */
	public static PrintWriter out;

	/**
	 * Construct the machine with the result file to print the results to.
	 * @param result
	 */
	public Machine(String result) {
		try {
			out = new PrintWriter(new FileWriter(result));
		} catch (IOException e) {
			System.out.println("cannot open file");
			e.printStackTrace();
		}
	}
	
	
	
	/**
	 * Main Program runs from here.
	 * @param arg File name to open
	 * @throws IOException 
	 */
	public void run(String arg) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

//		System.out.println("Please input the pl/0 file:");
//		String src = "C:\\Users\\Jeff Klenke\\workspace\\CSE_655_Project\\src\\testPrograms\\";
//		src = src.concat(in.readLine());
//		out.
		parser = new Parser(arg);

		parser.parseProgram();
		parser.seg.listcode();

		Interpreter interp = new Interpreter(parser.symbolTable, parser.seg);
		interp.interpret();
		parser.printTokens();
		parser.printSymbolTable();
		out.close();
	}
}
